<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Leave_model extends CI_Model
{
	
	public function __construct()
	{
		parent::__construct();

	}
	
	public function insert_user_leave($data)
	{
		 $query = $this->db->insert('user_leave', $data);	 
	}
	
	public function get_all_leaves()
	{		 
	 return $get = $this->db->get_where('user_leave', array('user_id' => $this->session->userdata('user_id')))->result();	
	}
	
	public function total_leaves()
	{
		return $get = $this->db->get_where('user_leave', array('user_id' => $this->session->userdata('user_id')))->num_rows();	
	}
	
	public function leave_remaining()
	{
		//$return = (12 - total_leave_granted());		 
	}
	
	public function total_leave_granted()
	{
		return $get = $this->db->get_where('user_leave', array('user_id' => $this->session->userdata('user_id'),'status'=>'approved'))->num_rows();	
	}
	
	
	public function get_pending_leaves()
	{
	return $get = $this->db->get_where('user_leave', array('user_id' => $this->session->userdata('user_id'),'status'=>'pending'))->result();
	}
	
	public function get_leave_status()
	{
		$this->db->select('*');
		$this->db->from('user_leave');
		$this->db->where('user_id =', $this->session->userdata('user_id'));
		$this->db->where('status !=', 'pending');
		return $this->db->get()->result();
		
		//return $get = $this->db->get_where('user_leave', array('user_id' => $this->session->userdata('user_id'),'status'=>'pending'))->result();
	}
	
	public function duplicate_date($date)
	{
		return $this->db->get_where('user_leave', array('user_id' => $this->session->userdata('user_id'),'leave_date'=>$date))->num_rows();
	}
	
	public function delete($id)
	{
		$this->db->delete('user_leave', array('id' => $id)); 
	}
	
	public function edit($edit_id)
	{
		return $this->db->get_where('user_leave',array('id'=>$edit_id))->row_array();
	}
	
	public function update($data,$edit_id)
	{
		$this->db->update('user_leave',$data,array('id'=>$edit_id));
	}
	
}
